home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: Bradd W. Szonye <bradds@ix.netcom.com>
- Newsgroups: comp.lang.c++
- Subject: RE: extending c++ to include type bool
- Date: 20 Apr 1996 00:22:59 GMT
- Organization: Netcom
- Message-ID: <01bb2e4f.c31ef2a0$d4c2b7c7@Zany.localhost>
- References: <bdsilver.829698454@extro> <3176C470.2647@cs.tu-berlin.de> <WALD.96Apr19094644@woodpecker.lcs.mit.edu>
- NNTP-Posting-Host: det-mi6-20.ix.netcom.com
- X-NETCOM-Date: Fri Apr 19 5:22:59 PM PDT 1996
- X-Newsreader: Microsoft Internet News
-
-
- On Friday, April 19, 1996, David Wald wrote...
- > In article <3176C470.2647@cs.tu-berlin.de> Roman Lechtchinsky
- > <wolfro@cs.tu-berlin.de> writes:
- > >Brett David Silverman wrote:
- > >> The question: Is it possible to create a class bool, in such a way
- > >> that it looks, smells, feels, talks, etc like the "real" bool? To
- > >> the extent that I can create this class so that I am guaranteed
- > >> that the source will work, even though I can't see the source?
- >
- > >I think one of the following should do ( depending on the compiler ):
- > >enum bool { false, true };
- > >or
- > >enum { false, true };
- > >typedef int bool;
- >
- > (Didn't we just go through this?) Thanks to overloading, it's not
- > possible for a user-defined type to completely emulate the C++ bool.
- > If you need a guarantee that some arbitrary code written with the C++
- > bool type will work with your user-defined type, you're out of luck.
- >
- > Consider:
- >
- > int f(bool);
- > int f(int);
- > int g(int a, int b) { return f(a == b); }
- >
- > In a system without built-in bool, no user-defined bool will result in
- > a call to f(bool). You can't change the type of a built-in comparison
- > operator.
- >
- > -David
-
- I've tried creating bool substitutes; you can do a fairly good job if you
- create a class to mimic the behavior of bool as closely as possible as
- specified in the working papers available on AT&T's web site. The main
- problem you'll run into is the way overloading handles integral promotions
- at a higher priority than user-defined conversions (class conversion
- operators).
-
- If you were *really* ambitious, you might be able to come up with an
- alternate preprocessor that reliably translates bools and bool expressions
- (including conditional and relational expressions). After all, that's how
- cfront works for the whole language. However, you might as well shell out
- $300ish for the real compiler from Borland, or wait for Microsoft to start
- supporting more of the draft standard.
-
- Speaking of which... Microsoft has trouble making MFC compatible with just
- the STL. How are they going to cope with some of the tougher changes and
- not break MFC? Hmmm.
-
- Bradd
-
-
-